<!DOCTYPE html >
<html>
<head>
<meta name="Generator" content="tpshop" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>購物車-{$tpshop_config['shop_info_store_title']}</title>
<meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
<meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<link rel="stylesheet" href="__STATIC__/css/public.css">
<link rel="stylesheet" href="__STATIC__/css/flow.css">
<link rel="stylesheet" href="__STATIC__/css/style_jm.css">
<script type="text/javascript" src="__STATIC__/js/jquery.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/mobile_common.js"></script>
<script src="__STATIC__/js/common.js"></script>
<link rel="stylesheet" href="__STATIC__/css/font-awesome.min.css">
<link rel="stylesheet" href="__STATIC__/css/icomoon.css">
</head>
<body>

<div class="tab_nav tab_nav_none">
    <div class="header">
      <div class="h-mid">購物車   </div>
    </div>
</div>

 
 <if condition="$promname">
    <div id="cart_top" style="margin-bottom: 0; text-indent:10px;">

        優惠： <select name="hd_id" id="hd_id" onchange="ajax_cart_list()" style="margin-right:10px; padding:5px 10px; font-size:12px; border:1px solid #dedede;">
            <foreach name="promname" item="v1" key="k1" >
                <option <if condition="$hd_id eq $v1[id]"> selected="selected" </if> value="{$v1[id]}">{$v1[name]}</option>
            </foreach>
        </select>
     </div>
     
     
      <else/>
            <div id="cart_top">
            <!--<span>滿￥{$freight_free} 可免郵費</span>-->
            <!--<a href="{:U('Mobile/Goods/goodsList')}">去看看<i class="fa fa-angle-right"></i></a>-->
            </div>
      </if>
 
<div class="screen-wrap fullscreen login">
    <div class="page-shopping ">
      <div class="cart_list">
        <form id="cart_form" name="formCart" action="{:U('Mobile/Cart/ajaxCartList')}" method="post">

        </form>
      </div>
    </div>
<div style="height:72px;"></div>
</div>
<div class="f_block" id="pop" style="position: fixed; bottom: 0px; left: 0px; height: 0px; z-index: 99999999; overflow: hidden; width: 100%; background: rgb(255, 255, 255);">
  <p class="f_title"><span>選擇自提點</span><a class="c_close" href="javascript:void(0)" onClick="close_pop()"></a></p>
  <div id="pickcontent"></div>
</div>


<include file="Public/footer_nav"/>
<script type="text/javascript">
$(document).ready(function(){
    ajax_cart_list(); // ajax 請求獲取購物車列表
});

// ajax 提交購物車
var before_request = 1; // 上壹次請求是否已經有返回來, 有才可以進行下壹次請求
function ajax_cart_list(){
	
	if($('#hd_id').val()!="undefined")
	{
    	var hd_id =$('#hd_id').val();
	}
	if(before_request == 0) // 上壹次請求沒回來 不進行下壹次請求
	    return false;
	before_request = 0;
	
    $.ajax({
        type : "POST",
        url:"{:U('Mobile/Cart/ajaxCartList')}",//+tab,
        data : $('#cart_form').serialize()+"&hd_id="+hd_id,// 妳的formid
        success: function(data){
            $("#cart_form").html('');
            $("#cart_form").append(data);
			before_request = 1;			
        }
    });
}

/**
 * 購買商品數量加加減減
 * 購買數量 , 購物車id , 庫存數量
 */
function switch_num(num,cart_id,store_count)
{
    var num2 = parseInt($("input[name='goods_num["+cart_id+"]']").val());
    num2 += num;
    if(num2 < 1) num2 = 1; // 保證購買數量不能少於 1
    if(num2 > store_count)
    {   alert("庫存只有 "+store_count+" 件, 妳只能買 "+store_count+" 件");
        num2 = store_count; // 保證購買數量不能多余庫存數量
    }
	
	$("#goods_num["+cart_id+"]").val(num2);
    $("input[name='goods_num["+cart_id+"]']").val(num2);

    ajax_cart_list(); // ajax 更新商品價格 和數量
}

// ajax 刪除購物車的商品
function ajax_del_cart(ids)
{
    $.ajax({
        type : "POST",
        url:"{:U('Mobile/Cart/ajaxDelCart')}",
        data:{ids:ids},
        dataType:'json',
        success: function(data){
            if(data.status == 1)
        	{
            	ajax_cart_list(); //ajax 請求獲取購物車列表	
        	}               
        }
    });
}

// 批量刪除購物車的商品
function del_cart_more()
{
    if(!confirm('確定要刪除嗎?'))
        return false;
    // 循環獲取復選框選中的值
    var chk_value = [];
    $('input[name^="cart_select"]:checked').each(function(){
        var s_name = $(this).attr('name');
        var id = s_name.replace('cart_select[','').replace(']','');
        chk_value.push(id);
    });
    // ajax調用刪除
    if(chk_value.length > 0)
        ajax_del_cart(chk_value.join(','));
}
</script> 
</body>
</html>